from .image_convert_base import ConvertBase
import cv2 as cv
import numpy as np


class ResizeConvert(ConvertBase):
    
    def __init__(self, target_size, use_rate = 0.5):
        super().__init__(use_rate)
        
        self.target_size = target_size
        
        
    def convert(self, img, boxes, points):
        h, w, _ = img.shape
        img = cv.resize(img, self.target_size)
        
        target_w, target_h = self.target_size
        
        w_scale = target_w / w
        h_scale = target_h / h
        
        if boxes is not None:
            boxes[:, 0] *= w_scale
            boxes[:, 1] *= h_scale
            boxes[:, 2] *= w_scale
            boxes[:, 3] *= h_scale
            
        if points is not None:
            points[:, 0] *= w_scale
            points[:, 1] *= h_scale
        
        return img, boxes, points
        
        
        
        